<?php

if ( !defined( 'BASEPATH' ) ) exit( 'No direct script access allowed' );

/**
 * 消息提示模块
 */
class MessageBox extends MY_Controller
{

    /**
     * 加载消息提示
     * @param array $data
     * @return string
     * @example
     * -------------------------------------------
     * $messageData = array(
      'title' => '操作成功',
      'message' => '欢迎成为会员，4秒后自动跳转回首页',
      'autoRedirect' => true,
      'autoRedirectTimeOut' => 4,
      'autoRedirectURL' => config_item( 'base_url' ),
      );
     * $messageBox = Modules::run( 'messageBox', $messageData );
     * -------------------------------------------
     */
    public function index( $data = array( ) )
    {
        $msgData = array(
            'title' => isset( $data['title'] ) ? htmlspecialchars( $data['title'] ) : '系统提示',
            'message' => isset( $data['message'] ) ? htmlspecialchars( $data['message'] ) : '',
            'autoRedirect' => isset( $data['autoRedirect'] ) ? $data['autoRedirect'] : false,
            'autoRedirectTimeOut' => (isset( $data['autoRedirectTimeOut'] ) && !empty( $data['autoRedirectTimeOut'] )) ? intval( $data['autoRedirectTimeOut'] ) : 5,
            'autoRedirectURL' => isset( $data['autoRedirectURL'] ) ? $data['autoRedirectURL'] : config_item( 'base_url' ),
        );
        return $this->load->view( 'messagebox_view', $data );
    }

}